#include "common.h"
#include "counter.h"
#include "svdpi.h"

long long mul_caculate(svBit is_mulh, svBit src_word, long long src1, long long src2, svBit src1_sign, svBit src2_sign);
long long div_caculate(svBit src_word, long long src1, long long src2, svBit src_sign, svBit is_rem);

void test_mul(svBit is_mulh, svBit src_word, long long src1, long long src2, svBit src1_sign, svBit src2_sign)
{
    long long res = 0;
    res = mul_caculate(is_mulh, src_word, src1, src2, src1_sign, src2_sign);
    LOG("MUL %lld * %lld => %lld, mulh [%d] word[%d] sign[%d,%d]", src1, src2, res, is_mulh, src_word, src1_sign, src2_sign);
}
void test_div(svBit src_word, long long src1, long long src2, svBit src_sign, svBit is_rem)
{
    long long res = 0;
    res = div_caculate(src_word, src1, src2, src_sign, is_rem);
    if (is_rem)
    {
        LOG("REM %lld %% %lld => %lld, word[%d] sign[%d]", src1, src2, res, src_word, src_sign);
    }
    else
    {
        LOG("DIV %lld / %lld => %lld, word[%d] sign[%d]", src1, src2, res, src_word, src_sign);
    }
}

int main()
{
    test_mul(0, 0, 0x100000000ull, 0x100000000ull, 0, 0);
    test_mul(0, 0, 0x100000000ull, 0x100000000ull, 1, 1);
    test_mul(0, 0, 0x100000000ull, 0x100000000ull, 1, 0);
    test_mul(0, 0, 0x100000000ull, 0x100000000ull, 0, 1);
    test_mul(0, 1, 0x100000000ull, 0x100000000ull, 0, 0);
    test_mul(0, 1, 0x100000000ull, 0x100000000ull, 1, 1);
    test_mul(0, 1, 0x100000000ull, 0x100000000ull, 1, 0);
    test_mul(0, 1, 0x100000000ull, 0x100000000ull, 0, 1);
    test_mul(1, 0, 0x100000000ull, 0x100000000ull, 0, 0);
    test_mul(1, 0, 0x100000000ull, 0x100000000ull, 1, 1);
    test_mul(1, 0, 0x100000000ull, 0x100000000ull, 1, 0);
    test_mul(1, 0, 0x100000000ull, 0x100000000ull, 0, 1);

    test_div(0, 99, 9, 0, 0);
    test_div(0, 99, 9, 1, 0);
    test_div(1, 99, 9, 0, 0);
    test_div(1, 99, 9, 1, 0);
    test_div(0, 100, 9, 0, 1);
    test_div(0, 100, 9, 1, 1);
    test_div(1, 100, 9, 0, 1);
    test_div(1, 100, 9, 1, 1);

    test_div(0, 99, 0, 0, 0);
    test_div(0, 99, 0, 1, 0);
    test_div(1, 99, 0, 0, 0);
    test_div(1, 99, 0, 1, 0);
    test_div(0, 100, 0, 0, 1);
    test_div(0, 100, 0, 1, 1);
    test_div(1, 100, 0, 0, 1);
    test_div(1, 100, 0, 1, 1);


    test_div(0, 99, -9ull, 1, 0);
    test_div(1, 99, -9ull, 1, 0);
    test_div(0, 100, -9ull, 1, 1);
    test_div(1, 100, -9ull, 1, 1);
}